package com.itheima.service.impl;

import com.itheima.entity.SysJobLog;
import com.itheima.dao.SysJobLogDao;
import com.itheima.service.SysJobLogService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (SysJobLog)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:52
 */
@Service("sysJobLogService")
public class SysJobLogServiceImpl implements SysJobLogService {
    @Resource
    private SysJobLogDao sysJobLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param jobLogId 主键
     * @return 实例对象
     */
    @Override
    public SysJobLog queryById(Long jobLogId) {
        return this.sysJobLogDao.queryById(jobLogId);
    }

    /**
     * 分页查询
     *
     * @param sysJobLog 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SysJobLog> queryByPage(SysJobLog sysJobLog, PageRequest pageRequest) {
        long total = this.sysJobLogDao.count(sysJobLog);
        return new PageImpl<>(this.sysJobLogDao.queryAllByLimit(sysJobLog, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param sysJobLog 实例对象
     * @return 实例对象
     */
    @Override
    public SysJobLog insert(SysJobLog sysJobLog) {
        this.sysJobLogDao.insert(sysJobLog);
        return sysJobLog;
    }

    /**
     * 修改数据
     *
     * @param sysJobLog 实例对象
     * @return 实例对象
     */
    @Override
    public SysJobLog update(SysJobLog sysJobLog) {
        this.sysJobLogDao.update(sysJobLog);
        return this.queryById(sysJobLog.getJobLogId());
    }

    /**
     * 通过主键删除数据
     *
     * @param jobLogId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long jobLogId) {
        return this.sysJobLogDao.deleteById(jobLogId) > 0;
    }
}
